<?php 
require_once("../../includes/_ClsCon.php");
$db = new MySQLi('localhost','root','12345','notarios');
$_obj   = new _ClsCon();        
	$estado    = $_POST['estado'];
	$numcarta = $_REQUEST['numcarta'];
	$nombrer = $_REQUEST['nombrer'];
	$nombred  = $_REQUEST['nombred'];
	$rangoc1  = $_REQUEST['rangoc1'];
	$rangoc2  = $_REQUEST['rangoc2'];
	
	$db = new MySQLi('localhost','root','12345','notarios');

	$limite = $_POST['limite'];
	$query2 = "SELECT id_carta FROM ingreso_cartas";
	$res2=$db->query($query2);
	$total=$res2->num_rows;
	
	$paginas=ceil($total/17);
	
    $query = "CALL spLisCartas('".$numcarta."' ,'".$nombrer."' ,'".$nombred."' ,'".$rangoc1."','".$rangoc2."','".$estado."',".$limite.")";
	
	$res = $db->query($query);
	
	if($res2->num_rows){
		
while ($rowkar = $res->fetch_array())
{	

$nomyape1=strtoupper($rowkar['nom_remitente']);
	$textorefe1=str_replace("?","'",$nomyape1);
	$textoampers1=str_replace("*","&",$textorefe1);
	$textoamperss1=str_replace("ñ","Ñ",$textoampers1);
	$refii1=strtoupper($textoamperss1);
	
	$nomyape=strtoupper($rowkar['nom_destinatario']);
	$textorefe=str_replace("?","'",$nomyape);
	$textoampers=str_replace("*","&",$textorefe);
	$textoamperss=str_replace("ñ","Ñ",$textoampers);
	$refii=strtoupper($textoamperss);
	
	
	
	$numcarta = $rowkar['num_carta'];
	$numcarta2 = substr($numcarta,5,6).'-'.substr($numcarta,0,4);
					
	$cartas[$rowkar['id_carta']]="<table width='858' border='1' cellpadding='0' cellspacing='0' bordercolor='#333333' >
  <tr>
    <td width='63' align='center' ><span class='reskar'><a href='EditCartasVie.php?numcarta=".strtoupper($rowkar['num_carta'])."'>".strtoupper($numcarta2)."</a></span></td>
	<td width='86' align='center' ><span class='reskar'>".strtoupper($rowkar['fec_ingreso'])."</span></td>
	<td width='86' align='center' ><span class='reskar'>".strtoupper($rowkar['fec_entrega'])."</span></td>
	<td width='200' align='center' ><span class='reskar'>".$refii1."</span></td>
    <td width='224' align='center'><span class='reskar'>".$refii."</span></td>
  </tr>
</table>";
}
}

	
foreach($cartas as $cart){
	
	echo "<article >".$cart."</article>";
	}		

echo "<table width='300' border='0' cellspacing='0'cellpadding='0'>
  <tr>
    <td width='45'>"; if ($limite>0){
	
	$limit=$limite-17;
	echo "<input type='hidden' value='".$limit."' id='_imagen' /><aside onClick=\"cargakardex(".$limit.")\"><img src='../../ante.png' width='37' height='36' border='0' title='Anterior'></aside>";
	
	}else{
		echo "<input type='hidden' value='".$limit."' id='_imagen' /><aside></aside>";
		}  echo"</td>
    		<td width='100'>";
			echo "total de pag :"." ".$paginas;
			echo"</td>
    <td width='50'>"; 
	
	if ($limite<$total-17){
	
	$limit=$limite+17;
	echo "<aside onClick=\"cargakardex(".$limit.")\"><img  src='../../sigte.png' width='37' height='36' border='0' title='Siguiente'></aside>";
	
	}else{
		echo "<aside></aside>";
		}
	
	echo"</td>
  </tr>
</table>";
?>
